package net.news.service;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import net.news.dao.NewsDao;
import net.news.dao.NewsPeopleDao;
import net.news.entity.News;
import net.news.entity.NewsPeople;

import org.springframework.stereotype.Service;

import com.liesp.util.ConstantUtils;
import com.liesp.util.PropertyFilter;
import com.opensymphony.xwork2.ActionContext;

/**
* 项目名称：cmunews3084<br>
* 类名称：NewsPeopleService <br>  
* 类描述：  TODO(请输入类的描述) <br>
* 创建人：charles   
* 创建时间：2011-5-10 下午10:40:30 <br> 
* 修改人：   
* 修改时间：                  <br>  
* 修改备注：   
* @version V1.0
*/
@Service
public class NewsPeopleService {
	@Resource
	private NewsPeopleDao newsPeopleDao;
	
	/** 用户登录方法
	 * @param newsPeople
	 * @return
	 */
	public NewsPeople userLogin(NewsPeople newsPeople){
		
		List<NewsPeople> people=newsPeopleDao.findNewsPeople(newsPeople);
		if (people.size()>0) {
			return people.get(0);
		}
		return null;
	}
	
	/**根据id查询管理员
	 * @param newsPeople 管理员实体
	 * @return
	 */
	public NewsPeople getNewsPeople(NewsPeople newsPeople){
		List<NewsPeople> entitys=newsPeopleDao.findNewsPeopleById(newsPeople);
		if (null!=entitys&&entitys.size()>0) {
			return entitys.get(0);
		}
		return null;
	}
	
	/**新增管理员
	 * @param newsPeople
	 */
	public void addNewsPeoPle(NewsPeople newsPeople){
		newsPeopleDao.savaNewsPeople(newsPeople);
	}
	
	/**根据用户名判断用户是否存在
	 * @param newsPeople 
	 * @return  返回flase为存在
	 */
	public boolean getNewsPeopleBoolean(NewsPeople newsPeople){
		List<NewsPeople> nps=newsPeopleDao.findNewsPeoplesBoolean(newsPeople);
		return nps!=null&&nps.size()>0?false:true;
	}
	
	/**查询所有管理员
	 * @param newsPeople 管理员实体
	 * @return
	 */
	public List<NewsPeople> getNps(){
		List<NewsPeople> npsList=newsPeopleDao.findNps();
		return npsList;
	}
	
	/**根据调教模糊查询管理员
	 * @param newsPeople 管理员实体类
	 * @return
	 */
	public List<NewsPeople> getNpList(List<PropertyFilter> filters){
		PropertyFilter pf1=new PropertyFilter("GTI_popleType",Integer.toString(0));
		filters.add(pf1);
		List<NewsPeople> npList=newsPeopleDao.findNPList(filters);
		return npList;
	}
	
	/**更新管理员方法
	 * @param newsPeople
	 */
	public void modifyNewsPeople(NewsPeople newsPeople){
		newsPeopleDao.merge(newsPeople);
	}
	
	/**删除管理员方法
	 * @param newsPeople
	 */
	public void deleteNewsPeople(NewsPeople newsPeople){
		NewsPeople newsPeople2=this.getNewsPeople(newsPeople);
		newsPeopleDao.deleteNewsPeople(newsPeople2);
	}
}
